package com.hyl.util;

import java.util.List;

/**
 * PageUtil
 *
 * @author hyl
 * @date 2025-07-04
 */
public class PageUtil<T> {

    private Integer pageNo; //页码
    private Integer pageSize; //每页显示的记录数
    private Integer totalCount; //总记录数
    private Integer totalPage;//总页数
    private List<T> list; //当前页的数据集合


    private Integer offset ;// 起始索引,limit 偏移量

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getTotalPage() {
        totalPage = totalCount%pageSize==0 ? totalCount/pageSize : totalCount/pageSize+1;
        return totalPage;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public Integer getOffset() {
        if (pageNo != null && pageSize != null) {
            offset = (pageNo - 1) * pageSize;
        }
        return offset;
    }
}
